<?php
class ArticleAction extends BaseAction{
	public function index(){
		$article = D("Article");
		import("ORG.Util.Page");
		$count = $article->count();          
		$Page = new Page($count,20);
		$show = $Page->show();
		$articles = $article->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('pages',$show);
		$this->assign("articles",$articles);
                $this->assign("title",'文章管理');
		$this->display("Public:article");
	}
	public function add(){
		$this->assign('id',Session::get(C('USER_AUTH_KEY')));
		$this->display("Public:article");
	}
	public function doadd(){
		$article = D("Article");
		if($article->Create()){
			if($article->add()){
				$this->assign("jumpUrl","__URL__");
				$this->success("发布成功！");
			}else{
				$this->error("发布失败！");
			}
		}else{
			$this->error($article->getError());
		}
	}
	public function edit(){
		if($_GET['id']){
			$article = D("Article")->getById($_GET['id']);
			$this->assign($article);

			$this->display("Public:article");
		}else{
			$this->assign("jumpUrl","__URL__");
			$this->error("数据不存在！");
		}
	}
	public function doedit(){
		$data = $_POST;
		$data['postdate'] = strtotime($_POST['postdate']);
		if(D("Article")->save($data)){
			$this->success("修改成功！");
		}else{
			$this->error("资料无改变或修改失败！");
		}
	}
	public function batch(){
		$this->_batch();
	}
}
?>